<?php namespace App\Services;

use App\Facades\Infra\WelfareManager;

class WelfareService{
	public function getWelfare($conditions){
		return WelfareManager::getWelfares($this->formatConditions($conditions));
	}

	public function getWelfares($conditions){
		return WelfareManager::getWelfares($this->formatConditions($conditions),true)->orderBy('created_at','desc')->paginate(15);
	}

	public function createWelfare($data){
		WelfareManager::createWelfare($this->formatData($data));
	}

	public function deleteWelfare($conditions){
		WelfareManager::deleteWelfare($conditions);
	}

	public function updateWelfare($data){
		$conditions['id'] = $data['id'];

		WelfareManager::updateWelfare($this->formatConditions($conditions),$data);
	}

	private function formatData($data){
		$data['hotel_id'] = \Auth::user()->id;

		return $data;
	}

	private function formatConditions($conditions){
		$conditions['hotel_id'] = \Auth::user()->id;

		return $conditions;
	}
}